#include<stdio.h>
#include<string.h>

struct info{
	char username[20];
	char password[20];
	}hash[20];

int size=0;
int insert(char username[],char password[])
{
	int i=0;
	int j,l;
	do{
		l=(int)(username[0])%size;
	        j=((l+i)%size);
		if(strcmp(hash[j].username,"")==0)
			{strcpy(hash[j].username,username);
			strcpy(hash[j].password,password);
			return j;
				}
		else		
			i=i+1;
	}while(i<size);
	return -1;
}


int search(char username[], char password[])
{
	int i,j,l;
	i=0;
	do{
		l=(int)(username[0])%size;
	        j=((l+i)%size);
		if(strcmp(hash[j].username,username)==0) 
			if(strcmp(hash[j].password,password)==0)
				return j;
		
		i=i+1;
	}while((strcmp(hash[j].username,"")!=0)&&(i<size));
	return -1;
}

void main()
{	int i,k,p,q,l;
	char name[20],pass[20];
	char name1[40];
	char password[40];
	FILE *f,*fr1;



	fr1=fopen("names.txt","r");
    p=getc(fr1);
    while(p!=EOF)
    {
        if(p=='\n')
        {
            size++; 
	}
            p=getc(fr1);   
     
	}
	
	
	f=fopen("names.txt","r");
	for(i=0;fscanf(f,"%s %s",name,pass)!= EOF;i++)
		insert(name,pass);
	for(q=0;q<3;q++)
	{
	printf("Enter the username \n");
	scanf(" %s",name1);
	printf("Enter the password \n");
	scanf(" %s",password);
	l=search(name1,password);
	if(l==-1)
	printf("login number %d failed \n",(q+1));
	else{
	printf("Succesful login at login %d \n",(q+1));
	break;
	}
	}
	if(l==-1)
	printf("u have no try left \n");

}
